package org.example.GC;

import java.util.*;

public class StringAndArray {
    public void setZeroes(int[][] matrix) {
        int[] zeroX = new int[matrix.length];
        int[] zeroY = new int[matrix[0].length];
        Arrays.fill(zeroX, 0);
        Arrays.fill(zeroY, 0);

        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                if (matrix[i][j] == 0) {
                    zeroX[i] = 1;
                    zeroY[j] = 1;
                }
            }
        }
        for (int i = 0; i < matrix.length; i++) {
            for (int j = 0; j < matrix[0].length; j++) {
                if (zeroX[i] == 1 || zeroY[j] == 1) {
                    matrix[i][j] = 0;
                }
            }
        }

    }

    public String longestCommonPrefix(String[] strs) {
        String result = "";
        Arrays.sort(strs, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o1.length() - o2.length();
            }
        });

        outer:
        for (int i = strs[0].length(); i > 0; i--) {
            boolean flag = true;
            for (int j = 1; j < strs.length; j++) {
                if (strs[j].equals("")) {
                    HashMap hashMap = new HashMap();
                    return result;
                }
                if (!strs[j].startsWith(strs[0].substring(0, i))) {
                    flag = false;
                    break;
                }
            }
            if (flag == true) {
                result = strs[0].substring(0, i);
                break outer;
            }
        }
        return result;
    }
}
